package com.longge;

public class MinimumAddedCoins {
    public int minimumAddedCoins(int[] coins, int target) {
        int n = coins.length;
        boolean[][] dp = new boolean[n + 1][target + 1];
        for (int i = 0; i <= n; i++) {
            dp[i][0] = false;
        }
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= target; j++) {
                if (dp[i - 1][j-1]) {
                    dp[i][j] = true;
                } else {
                    for (int k = 0; k < i; k++) {
                        if (dp[k][j - coins[i - 1]]) {
                            dp[i][j] = true;
                            break;
                        }
                    }
                }
            }
        }
        int res = 0;
        for (int j = 1; j <= target; j++) {
            if (!dp[n][j]) {
                res++;
            }
        }
        return res;
    }
}
